package com.example.evanzeng.viewpagertest.ViewPager;

import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Created by Evan Zeng on 2016/8/18.
 */

public class MyTransformation implements ViewPager.PageTransformer {


//    private static final float MIN_SCALE = 0.85f;
    private static final float MIN_SCALE = 0.85f;

    @Override
    public void transformPage(View page, float position) {
        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
        float rotate = 15 * Math.abs(position);  //可以控制2个图片间距和转角
//        float rotate = 5 * Math.abs(position);
        //position小于等于1的时候，代表page已经位于中心item的最左边，
        //此时设置为最小的缩放率以及最大的旋转度数
        if (position <= -1) {
            page.setScaleX(MIN_SCALE);
            page.setScaleY(MIN_SCALE);
            page.setRotationY(rotate);
        }//position从0变化到-1，page逐渐向左滑动
        else if (position < 0) {
            page.setScaleX(scaleFactor);
            page.setScaleY(scaleFactor);
            page.setRotationY(rotate);
        }//position从0变化到1，page逐渐向右滑动
        else if (position >= 0 && position < 1) {
            page.setScaleX(scaleFactor);
            page.setScaleY(scaleFactor);
            page.setRotationY(-rotate);
        }//position大于等于1的时候，代表page已经位于中心item的最右边
        else if (position >= 1) {
            page.setScaleX(scaleFactor);
            page.setScaleY(scaleFactor);
            page.setRotationY(-rotate);
        }
    }


////    private static final float MIN_SCALE = 0.85f;
//    private static final float MIN_SCALE_2 = 0.65f;
//    private static final float MIN_ALPHA = 0.5f;
//    private static final float MAX_ROTATE = 30;
//    private Camera camera = new Camera();
//    /**
//     * position取值特点：
//     * 假设页面从0～1，则：
//     * 第一个页面position变化为[0,-1]
//     * 第二个页面position变化为[1,0]
//     *
//     * @param page
//     * @param position
//     */
//    @Override
//    public void transformPage(View page, float position) {
//        float centerX = page.getWidth() / 2;
//        float centerY = page.getHeight() / 2;
////        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
////        float scaleFactor = Math.max(MIN_SCALE_2, 1 - Math.abs(position));
//        float rotate = 30 * Math.abs(position); //偏转角度
////        float rotate = 30 * Math.abs(position);
//
//        if (position < -1) {
//            Log.d("kunkun", "position < -1:" );
//        } else if (position < 0) {
////            page.setScaleX(scaleFactor);
////            page.setScaleY(scaleFactor);
//            Log.d("kunkun", "position < -0------:" );
//            page.setRotationY(rotate);
//        } else if (position >= 0 && position < 1) {
////            page.setScaleX(scaleFactor);
////            page.setScaleY(scaleFactor);
//            Log.d("kunkun", "position >= 0 && position < 1&&&&&&&&&&&" );
//            page.setRotationY(-rotate);
//        } else if (position >= 1) {
//            Log.d("kunkun", "position >= 1@@@@@@@@@@@@@@@@@@@@" );
////            page.setScaleX(scaleFactor);
////            page.setScaleY(scaleFactor);
//            page.setRotationY(-rotate);
//        }
//    }

//    @Override
//    public void transformPage(View page, float position) {
//        if (position < -1 || position > 1) {
//            page.setAlpha(MIN_ALPHA);
//            page.setScaleX(MIN_SCALE);
//            page.setScaleY(MIN_SCALE);
//        } else if (position <= 1) { // [-1,1]
//            float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
//            if (position < 0) {
//                float scaleX = 1 + 0.3f * position;
//                Log.d("google_lenve_fb", "transformPage: scaleX:" + scaleX);
//                page.setScaleX(scaleX);
//                page.setScaleY(scaleX);
//            } else {
//                float scaleX = 1 - 0.3f * position;
//                page.setScaleX(scaleX);
//                page.setScaleY(scaleX);
//            }
//            page.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
//        }
//    }

}
